package com.dragons.spring5_reactor.controller;

import com.dragons.spring5_reactor.entities.User;
import com.dragons.spring5_reactor.service.UserService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

@RestController
public class UserController {
    @Resource
    private UserService userService;
    @GetMapping("/user/{id}")//id 查询
    public Mono<User> geetUserId(@PathVariable int id) { return userService.getUserById(id); }
    @GetMapping("/user")//查询所有
    public Flux<User> getUsers() { return userService.getAllUser(); }
    @PostMapping("/saveuser")//添加
    public Mono<Void> saveUser(@RequestBody User user) {
        Mono<User> userMono = Mono.just(user);
        return userService.saveUserInfo(userMono);
    }
}
